/**
 * 
 */
package com.seadragon.app.ksr.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
import static com.seadragon.app.ksr.model.KsrConstants.FIELD_NAME_ADDRESSLINE1;
import static com.seadragon.app.ksr.model.KsrConstants.FIELD_NAME_CITY;
import static com.seadragon.app.ksr.model.KsrConstants.FIELD_NAME_STATE;
import static com.seadragon.app.ksr.model.KsrConstants.FIELD_NAME_ZIP;
import static com.seadragon.app.ksr.model.KsrConstants.ERROR_MESSAGE_KEY_FIELD_REQUIRED;
import com.seadragon.app.ksr.model.Address;

/**
 * @author yadong
 *
 */
public class AddressValidator implements Validator {

	public boolean supports(Class<?> clazz) {
		return Address.class.isAssignableFrom(clazz);
	}

	/* (non-Javadoc)
	 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
	 */
	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_NAME_ADDRESSLINE1, ERROR_MESSAGE_KEY_FIELD_REQUIRED);
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_NAME_CITY, ERROR_MESSAGE_KEY_FIELD_REQUIRED);
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_NAME_STATE, ERROR_MESSAGE_KEY_FIELD_REQUIRED);
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, FIELD_NAME_ZIP, ERROR_MESSAGE_KEY_FIELD_REQUIRED);
	}

}
